package com.offcn.student;

import com.csvreader.CsvReader;
import com.offcn.pojo.Student;

import java.io.*;
import java.util.ArrayList;
import java.util.List;

public class StudentP {
    public static void main(String[] args) throws IOException {
        File file = new File("F:/soucer/student.csv");
        FileReader fileReader = new FileReader(file);
        CsvReader reader = new CsvReader(fileReader);
        reader.readHeaders();
        List<String[]> list = new ArrayList<>();
        while (reader.readRecord()){
            list.add(reader.getValues());
        }
        reader.close();
        String[] str= null;
        List<Student> stuList = new ArrayList<>();
        for (int i =0 ;i<list.size();i++){
            str=list.get(i);
            Student student= new Student();
            student.setStuId(Integer.parseInt(str[0]));
            student.setName(str[1]);
            student.setChinese(Integer.parseInt(str[2]));
            student.setMath(Integer.parseInt(str[3]));
            student.setEnglish(Integer.parseInt(str[4]));
            student.setWuli(Integer.parseInt(str[5]));
            student.setHuaxue(Integer.parseInt(str[6]));
            student.setShengwu(Integer.parseInt(str[7]));
            stuList.add(student);
        }
        for (int p =0;p<stuList.size();p++){
            for (int f = 0;f<stuList.size()-1;f++){
                if (stuList.get(f+1).getZong()>stuList.get(f).getZong()){
                    swap(stuList,f,f+1);
                }

                if (stuList.get(f+1).getZong().equals(stuList.get(f).getZong())){
                    if (stuList.get(f+1).getStuId()>stuList.get(f).getStuId()){
                        swap(stuList,f,f+1);
                        System.out.println(stuList.get(f));
                    }
                }
            }
        }
        for (Student s:stuList){
            System.out.println(s);
        }
    }


    public static void swap(List original, int i, int j) {
        Object temp = original.get(i);
        original.set(i, original.get(j));
        original.set(j, temp);
    }
}
